#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
using namespace std;
class Solution {
public:
    int trap(vector<int>& height) {
        int max = 0;
        vector<int> maxs;
        for (int i = 0; i < height.size(); i++)
        {
            max = max > height[i] ? max : height[i];
            maxs.push_back(max);
        }
        max = 0;
        int ans = 0;
        for (int i = height.size() - 1; i >= 0; i--)
        {
            max = max > height[i] ? max : height[i];
            maxs[i]=max<maxs[i]?max:maxs[i];
            ans += maxs[i] - height[i];
        }
        return ans;
    }
};
int main()
{
    Solution sol;
}